using AutoMapper;
using Blog.Repository;
using Blog.Service;
using Blog.Service.User.Input;
using Blog.Service.User.Output;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XjjXmm.Infrastructure.Repository;
using XjjXmm.Infrastructure.Repository.Model;
using XjjXmm.Infrastructure.User;

namespace Blog.Service.User
{
    /// <summary>
    /// 用户服务
    /// </summary>
    public class UserService : CrudService<UserModel, UserEntity>, IUserService
    {
        // private readonly AppConfig _appConfig;
        private readonly IUserRepository _userRepository;
        // private readonly IUserRoleRepository _userRoleRepository;
        //  private readonly ITenantRepository _tenantRepository;
        //private readonly IApiRepository _apiRepository;

        // private IRoleRepository _roleRepository => LazyGetRequiredService<IRoleRepository>();

        public UserService(IUserRepository userRepository, IUser user, IMapper mapper) : base(userRepository, user, mapper)
        {
            _userRepository = userRepository;
        }

        //public UserService(
        //    // AppConfig appConfig,
        //    IUserRepository userRepository,
        //    IUserRoleRepository userRoleRepository
        //// ITenantRepository tenantRepository,
        ////IApiRepository apiRepository
        //)
        //{
        //    // _appConfig = appConfig;
        //    _userRepository = userRepository;
        //    _userRoleRepository = userRoleRepository;
        //    //_tenantRepository = tenantRepository;
        //    //_apiRepository = apiRepository;
        //}



        public async Task<PageOutput<UserListOutput>> Page(PageInput<UserListInput> input)
        {
            //var list = await _userRepository.Select
            //.WhereDynamicFilter(input.DynamicFilter)
            //.Count(out var total)
            //.OrderByDescending(true, a => a.Id)
            //.IncludeMany(a => a.Roles.Select(b => new RoleEntity { Name = b.Name }))
            //.Page(input.CurrentPage, input.PageSize)
            //.ToList();

            //var data = new PageOutput<UserListOutput>()
            //{
            //    List = Mapper.Map<List<UserListOutput>>(list),
            //    Total = total
            //};

            //return data;

            //var dto = input.MapTo<PageInput<UserListInput>, PageInput<UserEntity>>();

            var users = await _userRepository.Queryable().ToPage(input.CurrentPage, input.PageSize);
            var entity = _mapper.Map<PageOutput<UserListOutput>>(users);


            return entity;
        }


    }
}